C (69/254)

From:Colin Wenzel
Date:20 Apr 00 at 08:58:46
Subject:Re: How to change stack

On 20-Apr-00, Andrzej J. Debicki wrote:

> Hello Colin,
>
> Wednesday, April 19, 2000, you wrote:
>> [...about StackSwap and StackSwapStruct...]
>
> Thanks. I wrote some test proggy. But something id wrong. It hangs on
> first StackSwap func. Can someone help me to solve that?
>
> #include <exec/memory.h>
> #include <exec/types.h>
> #include <clib/alib_protos.h>
>
> int main(void)
> {
> struct StackSwapStruct *pNewStack;
> struct Task *pTask;
> APTR pStackMem;
> ULONG lStackSize;
>
> pTask = (struct Task*)FindTask(NULL);
> lStackSize = (ULONG)pTask->tc_SPUpper - (ULONG)pTask->tc_SPLower +
> 16386;
> pNewStack = (struct StackSwapStruct*)AllocVec(sizeof(struct
> StackSwapStruct), MEMF_ANY|MEMF_CLEAR);
>
> Printf("Debug - 1\n");
>
> if(pNewStack)
> {
> pStackMem = (APTR)AllocVec(lStackSize, MEMF_ANY|MEMF_CLEAR);
>
> Printf("Debug - 2\n");
>
> if(pStackMem)
> {
> pNewStack->stk_Lower = pStackMem;
> pNewStack->stk_Upper = (ULONG)pStackMem + lStackSize;

> * pNewStack->stk_Pointer = (APTR)pNewStack->stk_Upper;*

This should be the *CURRENT* contents of A7 (sp)
I presume that is: *pNewStack->stk_Pointer = pTask->tc_SPReg;*

It needs to copy the current contents of your old stack at this point.

Cant be 100% sure, cause I do the stackswap in assembler
& just use the register SP.

>
> StackSwap(pNewStack);
>
> Printf("Debug - 3\n");
>
> /* rest of program */
>
> StackSwap(pNewStack);
>
> Printf("Debug - 4\n");
>
> FreeVec(pStackMem);
> }
>
> Printf("Debug - 5\n");
>
> FreeVec(pNewStack);
> }
> return 0;
> }
>
>
> I can see only:
> Debug - 1
> Debug - 2
>
> and then GURU :-(. I tried vbcc and StormC 3.
>
Regards



-------------------------------------
Colin Wenzel. Australia.

EMAIL: mailto:colstv@hotkey.net.au
URL: http://www.hotkey.net.au/~colstv/
ICQ: 17608330
AMIGA: 4000T, 68060/50, 150Mb RAM,
OS 3.5, EGS Spectrum.
---------------------------------------

------------------------------------------------------------------------
INSTANT RESEARCH. Check out Hoover's Online: Info on 50,000+
companies, 300 industries, IPO coverage, stock information &
more. Click here!
http://click.egroups.com/1/3410/1/_/451227/_/956217679/
------------------------------------------------------------------------